package org.example.onetry.servlet;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.example.onetry.service.impl.serviced;
import org.example.onetry.service.studentservicec;
import org.example.onetry.user.users;
import java.io.IOException;
import java.util.List;
@WebServlet (urlPatterns = {"/mx"})
public class mx extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpServletRequest request = (HttpServletRequest) servletRequest;
       /** response.setContentType("text/html");
        request.setCharacterEncoding("UTF-8");

//只使用业务层，把数值传递到jsp，从而在网页上形成展示
        **/
        studentservicec serviced=new serviced();
        List<users> cs=serviced.querystudent();
        /**
        response.getWriter().println("<table border=\"1\"cellspacing=\"0\" cellpadding=\"6\" >");
for(users u:cs){
response.getWriter().println("<tr>");
response.getWriter().println("<td>"+u.getId()+"</td>");
    response.getWriter().println("<td>"+u.getNa()+"</td>");
    response.getWriter().println("<td>"+u.getCon()+"</td>");
response.getWriter().println("</tr>");
}
response.getWriter().println("</table>");
        response.getWriter().println("<div>"+"<a href='index.html'>"+"回到首页"+"</a>"+"</div>");
         **/
        //去掉之前所有输出浏览器的操作，将数据绑定在request，有请求转发跳转到jsp实现数据展示，不保存在session是因为数据量多，是因为session保存到内容是保存在服务器上的，会对服务器造成很大压力，绑定在请求上同样可以实现传递(仅限于jsp，因为jsp能这样接受，两个servlet之间的传递还是要用session)
        request.setAttribute("cs",cs);
        request.getRequestDispatcher("student.jsp").forward(request, response);
    }

}
